#include <iostream>
#include <stack>
#include <algorithm>

using namespace std;

class Solution {
public:
    int calculate(string s) {
        stack<char> operate_stack;
        stack<int> num_stack;
        if (s.size() == 0) {
            return 0;
        }
        operate_stack.push('+');
        bool is_num = false;
        int num_begin = 0;
        int num_length = 0;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] >= '0' && s[i] <= '9') {
                if (!is_num) {
                    is_num = true;
                    num_begin = i;
                }
                num_length++;
                if (i == s.size() - 1) {
                    goto process;
                }
            } else {
                process:
                if (is_num) {
                    int val = atoi(s.substr(num_begin, num_length).data());
                    is_num = false;
                    num_length = 0;
                    if (operate_stack.size() > 0 && (operate_stack.top() == '*' || operate_stack.top() == '/')) {
                        if (operate_stack.top() == '*') {
                            val = num_stack.top() * val;
                        } else if (operate_stack.top() == '/') {
                            val = num_stack.top() / val;
                        }
                        num_stack.pop();
                        operate_stack.pop();
                    }
                    num_stack.push(val);
                }
                if (s[i] == '+') {
                    operate_stack.push('+');
                } else if (s[i] == '-') {
                    operate_stack.push('-');
                } else if (s[i] == '*') {
                    operate_stack.push('*');
                } else if (s[i] == '/') {
                    operate_stack.push('/');
                }
            }
        }
        int ans = 0;
        while (operate_stack.size() > 0) {
            char operate = operate_stack.top();
            int val = num_stack.top();
            operate_stack.pop();
            num_stack.pop();
            if (operate == '-') {
                val = -val;
            }
            ans += val;
        }
        return ans;
    }
};

int main() {
    Solution solution;
    int output = solution.calculate("1-1+1");
    cout << output << endl;
    return 0;
}
